import {page, pageFunc} from "../common/PageBuilder";
import {BasePage, BasePageData} from "../common/core/BasePage";
import {UserPage} from "../common/partPages/UserPage";
import {QueryPage} from "../common/partPages/QueryPage";
import {userMgr, waitForLogin} from "../../modules/userModule/managers/UserManager";
import {waitForDataLoad} from "../../modules/coreModule/managers/DataManager";
import {TaskInterface} from "../../modules/taskModule/TaskCommon";
import {DataLoader, field} from "../../modules/coreModule/data/DataLoader";
import {TaskIndexData} from "../../modules/taskModule/data/Task";

class Data extends BasePageData {

	@field([TaskIndexData])
	list: TaskIndexData[] = TaskIndexData.testData();
}

@page("myPub", "我的发布")
export class MyPubPage extends BasePage<Data> {

	public data = new Data();

	@pageFunc
	onLoad(e) {
		super.onLoad(e);
		this.queryPage.refresh();
	}

	/**
	 * 部分页
	 */
	public userPage: UserPage = new UserPage();
	public queryPage: QueryPage = new QueryPage(
		this.loadData.bind(this), {
			userId: userMgr().openid
		});

	/**
	 * 数据回调
	 */
	@waitForLogin
	@waitForDataLoad
	public async loadData(queryParams) {
		// queryParams.filter.userId = userMgr().openid;
		const res = await TaskInterface.GetTasks({
			...queryParams,
			sortTime: -1 // Desc
		})
		const list = res.tasks?.map(
			t => DataLoader.load(TaskIndexData, t));
		return list && this.setData({list});
	}

}
